package com.qigao.mall.service.impl;

import com.qigao.mall.api.TradeTotalService;
import com.qigao.mall.jdbc.mapper.TbTradeTotalMapper;
import com.qigao.mall.jdbc.model.TbOrderTotal;
import com.qigao.mall.jdbc.model.TbTradeTotal;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author luiz
 * @Title: com.qigao.mall.service.impl
 * @ProjectName market-parent
 * @date 2020-06-2020-06-19 14:51
 * @Description:
 */
@Service
public class TradeTotalServiceImpl implements TradeTotalService {
    @Resource
    private TbTradeTotalMapper tbTradeTotalMapper;
    @Override
    public void insertBatch(List<TbTradeTotal> tbTradeTotals) {
        tbTradeTotalMapper.insertBatch(tbTradeTotals);
    }

    @Override
    public void insert(TbTradeTotal tbTradeTotal) {
        tbTradeTotalMapper.insertSelective(tbTradeTotal);
    }

    @Override
    public void saveBatch(List<TbTradeTotal> tbTradeTotals) {
        for(TbTradeTotal tbTradeTotal:tbTradeTotals){
            TbTradeTotal tbTradeTotal1=tbTradeTotalMapper.selectByUniqIndex(tbTradeTotal.getSettleDate(),tbTradeTotal.getGroupNo(),tbTradeTotal.getItemCode());
            if(tbTradeTotal1!=null){
                tbTradeTotal.setId(tbTradeTotal1.getId());
                tbTradeTotal.setVersion(tbTradeTotal1.getVersion());
                tbTradeTotalMapper.addTradeAmtById(tbTradeTotal);
            }else{
                tbTradeTotalMapper.insertSelective(tbTradeTotal);
            }

        }

    }
}
